package com.JustTest;

import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;

/**
 * Created by mike on 18/4/8.
 */
public class Main {
    //    static{
//        StringBuilder a = new StringBuilder();
//        for(long i=0;i<1000000;i++) {
//            a.append("StringBuilderStringBuilderStringBuilderStringBuilderStringBuilderStringBuilderStringBuilderStringBuilderStringBuilder");
//        }
//        System.out.println(a.toString());
//    }
    public static void main(String[] args) throws UnknownHostException, SocketException, UnsupportedEncodingException {
//      while(true){
//
//      }
//        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
//        Bean1 bean = (Bean1)context.getBean("bean1");
//        System.out.println("name = [" + bean.getName() + "]");

//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("cluster.name", "elasticsearch");
//        map.put("client.transport.sniff", "true");
//        map.put("node.name", "node-1");
//        Settings.Builder settings = Settings.builder().put(map);
//        TransportClient client = TransportClient.builder().settings(settings).build().addTransportAddress(
//                       new InetSocketTransportAddress(new InetSocketAddress("192.168.60.103", 9200)));
//
//
//                List<DiscoveryNode> discoveryNodes = client.filteredNodes();
//        for(DiscoveryNode node:discoveryNodes){
//            System.out.println(node.getName());
//        }
//        //http://192.168.60.103:9200/_plugin/head/
//        GetResponse response = client.prepareGet("flat", "roomdetail", "1615816")
//                .setOperationThreaded(false)    // 线程安全
//                .get();
//        System.out.println(response.getSourceAsString());


//
//        //集群名
//        String clusterName = "elasticsearch";
//        //HTTP节点列表
//        String httpNodes = "http://192.168.60.103:9200";
//        //RPC节点列表
//        String rpcNodes = "192.168.60.103:9300";
//        esHttpNodeList = getServerUrls(httpNodes, 0);
//
//        List<EsNode> esNodeList = getServerUrls(rpcNodes, 1);
//
//        Settings settings = ImmutableSettings.settingsBuilder()
//                .put("cluster.name", clusterName)
//                .put("client.transport.sniff", true)
//                .build();
//        TransportClient transClient = new TransportClient(settings);
//
//        if(CollectionUtils.isNotEmpty(esNodeList)){
//            for(EsNode esNode : esNodeList){
//                if(null==esNode || StringUtils.isBlank(esNode.getIp())){
//                    continue;
//                }
//
//                transClient.addTransportAddress(
//                        new InetSocketTransportAddress(new InetSocketAddress(esNode.getIp(), esNode.getPort())));
//            }
//        }
//
//        return transClient;


        Enumeration<NetworkInterface> networks = NetworkInterface.getNetworkInterfaces();
        while (networks.hasMoreElements()) {
            NetworkInterface networkInterface = networks.nextElement();
            String networkName = networkInterface.getName();
            Enumeration<InetAddress> inetAddresss = networkInterface.getInetAddresses();
            while (inetAddresss.hasMoreElements()) {
                InetAddress inetAddress = inetAddresss.nextElement();
                System.out.println("name=" + networkName + "--------hostname=" + inetAddress.getHostName() + "--------address=" + inetAddress.getHostAddress()
                +"-------inteladdress="+ new String(inetAddress.getAddress(),"utf-8"));
            }

        }


    }
}
